Skip to content

fix: exclude VASP data generator from pytest - #387

Open
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/issue-361-pytest-data-generator
Open

fix: exclude VASP data generator from pytest#387
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/issue-361-pytest-data-generator

Conversation

@njzjz-bot

Copy link
Copy Markdown

Summary

  • rename the VASP fixture generator so it no longer matches pytest collection patterns
  • move generation into a documented main() function
  • import cellpar_to_cell directly instead of relying on ase.geometry as a module attribute

Tests

  • pytest --collect-only -q tests/fp/data.vasp.kp.gf (no tests collected, no import-time failure)
  • ruff format --check tests/fp/data.vasp.kp.gf/make_kp_data.py
  • isort --check-only tests/fp/data.vasp.kp.gf/make_kp_data.py
  • git diff --check

Closes #361

Coding agent: Codex
Codex version: codex-cli 0.149.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 23, 2026
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 59 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e833338c-d568-40b9-b114-dc0667bec9ce

📥 Commits

Reviewing files that changed from the base of the PR and between 6b01f29 and 9e16f04.

📒 Files selected for processing (2)
  • tests/fp/data.vasp.kp.gf/make_kp_data.py
  • tests/fp/data.vasp.kp.gf/make_kp_test.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.43%. Comparing base (6b01f29) to head (9e16f04).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #387   +/-   ##
=======================================
  Coverage   84.43%   84.43%           
=======================================
  Files         104      104           
  Lines        6110     6110           
=======================================
  Hits         5159     5159           
  Misses        951      951           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Rename the fixture generator outside pytest patterns and guard generation behind an explicit main entry point.

Closes deepmodeling#361

Coding-Agent: Codex
Codex-Version: codex-cli 0.149.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz-bot
njzjz-bot force-pushed the fix/issue-361-pytest-data-generator branch from d3e0f9f to 9e16f04 Compare August 26, 2026 11:00
wanghan-iapcm

This comment was marked as outdated.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 27, 2026
@wanghan-iapcm
wanghan-iapcm dismissed their stale review August 27, 2026 03:33

Retracted: submitted without the maintainer's decision. Will re-review and let the maintainer choose the action.

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rename is right and I verified it fixes a real failure. Blocking only on the docstrings, which now advertise a regeneration workflow that corrupts the fixtures.

The fix works

With the old filename restored, pytest --collect-only -q tests/fp/data.vasp.kp.gf gives

ERROR tests/fp/data.vasp.kp.gf/make_kp_test.py - FileNotFoundError: [Errno 2] No such file or directory: 'POSCAR'
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!

At this head it reports "no tests collected", clean. The repository configures no python_files, so pytest's default ["test_*.py", "*_test.py"] applies and the old name matched the second pattern. Nothing anywhere in the tree references the generator by either name, so the rename breaks nothing.

Two corrections to the record while I am here, neither of which changes the verdict on the rename.

The AttributeError: module 'ase' has no attribute 'geometry' quoted in #361 does not actually fire. A bare import ase really does hide ase.geometry in ase 3.28, but import dpdata binds it as a side effect, and the old file imported dpdata. With the old import order the attribute access succeeds, which is why the collection error above is a FileNotFoundError raised on the line after cellpar_to_cell. Importing the function directly is still worth doing, since relying on a third-party package's import graph is fragile, but it is hardening rather than a fix for an observed error.

And the blast radius is smaller than the issue suggests: CI runs coverage run ... -m unittest, whose default discovery pattern test*.py never matched this file. This is a local-developer fix. Note that #388 does not change that either, it only declares the dependency.

Blocking: main() regenerates half of each fixture

The PR adds a module docstring saying the script regenerates the k-point test data, a main() documented as regenerating all fixture directories, and a __main__ guard. Together these turn a script that previously only ran by accident into one a maintainer is invited to run. But make_one writes only POSCAR. Each test.NNN/ also holds a kp.ref, which tests/fp/test_vasp.py loads and compares against; nothing in the repository writes those.

So following the new docstring desynchronizes the two halves:

$ cd tests/fp/data.vasp.kp.gf && python make_kp_data.py     # exit 0, all 30 POSCARs replaced
$ pytest tests/fp/test_vasp.py -k make_kp
FAILED tests/fp/test_vasp.py::TestVASPInputs::test_make_kp - AssertionError: False is not true

Recomputing make_kspacing_kpoints(cell, 0.16, False) for each directory afterwards, all 30 disagree with their committed kp.ref.

Either is fine by me: have make_one also write kp.ref alongside the POSCAR, or reword the docstrings so they do not promise a complete regeneration and say the references must be redone by hand. What should not ship is a documented entry point that quietly breaks the suite.

Not blocking

make_one reads a bare "POSCAR" and main writes bare test.NNN/, so the new entry point only works when the current directory is exactly the fixture directory; from the repository root it exits 1 with the same FileNotFoundError that caused the original bug. Anchoring both to Path(__file__).parent would make the __main__ guard robust rather than merely lucky, and the file is already open.

Separately, and definitely not for this PR: the angle sampling has been wrong since the file was created in 2022. # [1, 179) sits above np.random.random(3) * (178 / 180) + 1, which yields angles in [1, 1.99) degrees, so every fixture is a nearly collinear cell. Measured across the 30 committed POSCARs, all 90 angles fall between 1.0007 and 1.9848 degrees, and test.000/kp.ref is 3012 1844 2485. The test therefore never exercises ordinary cells. I mention it because you are rewriting this file, but if anyone picks it up: the obvious correction * 178 + 1 is not safe. Uniformly random angle triples are usually not realizable as a parallelepiped, and 143 of 200 sampled triples tripped ase's cz_sqr >= 0 assertion. It needs rejection sampling, and regenerating kp.ref along with it.

On merge order: this conflicts with #405, which modifies make_kp_test.py while this PR deletes it (CONFLICT (modify/delete)). #382, #383, #384 and #386 all merge clean.



def main(ntest=30):
"""Regenerate all randomized fixture directories."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring, and the module one on line 2, promise a regeneration this function does not perform. make_one writes only POSCAR, but each test.NNN/ directory also contains a kp.ref that tests/fp/test_vasp.py compares computed k-points against, and nothing in the repository writes those.

Running exactly what the docstrings advertise:

$ cd tests/fp/data.vasp.kp.gf && python make_kp_data.py     # exit 0
$ pytest tests/fp/test_vasp.py -k make_kp
FAILED tests/fp/test_vasp.py::TestVASPInputs::test_make_kp - AssertionError: False is not true

and recomputing afterwards, all 30 directories disagree with their committed kp.ref.

Before this PR the loop only ran by accident at import time, so this was a latent hazard. Adding main(), the __main__ guard and these docstrings makes it an invitation. Either write kp.ref here too (make_kspacing_kpoints(cell, 0.16, False)), or say in the docstring that the references are not regenerated and must be redone by hand.

# [1, 179)
[alpha, beta, gamma] = np.random.random(3) * (178 / 180) + 1
cell = cellpar_to_cell([aa, bb, cc, alpha, beta, gamma])
system = dpdata.System("POSCAR")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but worth fixing while the file is open: this reads a bare relative "POSCAR", and main writes bare relative test.NNN/ directories, so the newly advertised entry point only works when the current directory is exactly tests/fp/data.vasp.kp.gf. From the repository root it exits 1 with FileNotFoundError: 'POSCAR' -- the same error that made pytest collection fail in the first place, since pytest imports collected modules with the working directory at the rootdir.

Anchoring both paths to Path(__file__).parent makes the __main__ guard robust instead of dependent on where it is invoked from.

# [0.5, 1)
[aa, bb, cc] = np.random.random(3) * 0.5 + 0.5
# [1, 179)
[alpha, beta, gamma] = np.random.random(3) * (178 / 180) + 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carried over unchanged from the old file, so not something this PR introduced, and I am not asking for it here. Recording it because the file is being rewritten and the comment is false.

178 / 180 is about 0.9889, so this yields angles in [1, 1.99) degrees, not [1, 179). cellpar_to_cell takes degrees, so every generated cell is nearly collinear. I measured all 90 angles across the 30 committed fixtures: 1.0007 to 1.9848 degrees. That is also why test.000/kp.ref reads 3012 1844 2485 -- k-point counts in the thousands only happen for cells this flat at kspacing 0.16. So test_make_kp has effectively no coverage of the ordinary-cell regime.

If anyone fixes this: * 178 + 1 is not the answer. Uniformly random angle triples are usually not geometrically realizable, and 143 of 200 samples I tried raised ase's cz_sqr >= 0 assertion. It needs rejection sampling, plus regenerating kp.ref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Exclude VASP k-point data generator from pytest collection

2 participants